/**
 * @file main.cc
 * @author Xiaoze Lin (linxiaoze96@gmail.com)
 * @brief The main function of fault sim.
 * @version 0.1
 *
 * @copyright Copyright (c) 2024
 *
 */

#include <iostream>

#include "fsim/Fsim.hh"
#include "log/Log.hh"
#include "usage/usage.hh"

using namespace ifsim;

using ieda::Log;
using ieda::Stats;

int main(int argc, char** argv)
{
  ieda::Stats stats;
  Log::init(argv);

  std::string hello_info = "\033[49;32mWelcome to functional pattern fault simulator.\033[0m\n";

  if (argc != 6) {
    std::cout << "argument count less than 5\n";
    std::cout << "argument: library, netlist, module name, fault list, vcd\n";

  } else {
    Fsim* ifsim = Fsim::getOrCreateFsim();
    // read library
    ifsim->readLibrary(argv[1]);

    // read and build netlist
    ifsim->readVerilog(argv[2]);
    ifsim->setCircuitHandling();
    ifsim->topModuleName(argv[3]);
    ifsim->genAndProcessNetlists();

    // read fault list
    ifsim->readFaultList(argv[4]);

    // read func pat
    ifsim->readPattern(argv[5]);

    // fault sim
    int num_thread = 4;  // num of running threads
    bool is_bit_parallel = true, is_vec_mode = true;
    ifsim->simulatePatterns(num_thread, is_bit_parallel, is_vec_mode);
  }

  Log::end();

  std::cout << "Total elapsed time: " << stats.elapsedRunTime() << "s" << std::endl;

  return 0;
}